#!/usr/bin/env python
# --*--coding:utf-8--*--

from app.core.base_class import MyBase
from app.core.model import g_dwsdataManager

class EtlMysqlExcutor(MyBase):

    def __init__(self):
        super(MyBase, self).__init__()
        self.debug('EtlMysqlExcutor init start...')
        self.debug('EtlMysqlExcutor init completed.')
        pass

    def set_connection(self, connection):
        self.conn = connection 

    def parse_sql(self):
        self.sql='SELECT * FROM new_table where id = {id}'.format(id='1')

    def execute(self, sql=None):
        self.debug('execute start...')
        if sql:
            self.sql = sql
        else:
            self.parse_sql()
        self.debug('sql text: %s' % self.sql)
        self.conn.execute(self.sql)
        #for r in self.conn.execute(self.sql).fetchall():
        #    print r
        self.debug('execute end.')
    
    def close(self):
        self.conn.close()

if __name__ == '__main__':
    etl_excutor = EtlMysqlExcutor()
    etl_excutor.set_connection(g_dwsdataManager.get_connection())
    #etl_excutor.execute('select * from new_table')
    etl_excutor.execute()
    etl_excutor.close()
